package org.wishwork.api.product.common.upload;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wishwork.api.Api;
import org.wishwork.context.Context;
import org.wishwork.helper.HttpHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 普通商品资料上传
 * @author: WangYX
 * @create: 2022-04-08 17:43
 * @Version: 1.0.0
 **/

public class CommonProductUploadApi extends Api<CommonProductUploadResponse, List<CommonProductUploadRequest>> {

    private static final Logger log = LoggerFactory.getLogger(CommonProductUploadApi.class);

    private Context context;

    public CommonProductUploadApi(Context context) {
        this.context = context;
    }

    @Override
    protected String query(List<CommonProductUploadRequest> commonProductUploadRequests) throws Exception {
        String url = "/open/jushuitan/itemsku/upload";
        List<Map<String, Object>> list = new ArrayList<>();
        if (commonProductUploadRequests != null && commonProductUploadRequests.size() > 0) {
            commonProductUploadRequests.forEach(o -> {
                Map<String, Object> map = new HashMap<>();
                if (StrUtil.isNotEmpty(o.getSkuId())) {
                    map.put("sku_id", o.getSkuId());
                }
                if (StrUtil.isNotEmpty(o.getIId())) {
                    map.put("i_id", o.getIId());
                }
                if (StrUtil.isNotEmpty(o.getBrand())) {
                    map.put("brand", o.getBrand());
                }
                if (StrUtil.isNotEmpty(o.getVcName())) {
                    map.put("vc_name", o.getVcName());
                }
                if (StrUtil.isNotEmpty(o.getCName())) {
                    map.put("c_name", o.getCName());
                }
                if (ObjectUtil.isNotEmpty(o.getSPrice())) {
                    map.put("s_price", o.getSPrice());
                }
                if (StrUtil.isNotEmpty(o.getItemType())) {
                    map.put("item_type", o.getItemType());
                }
                if (ObjectUtil.isNotEmpty(o.getL())) {
                    map.put("l", o.getL());
                }
                if (ObjectUtil.isNotEmpty(o.getW())) {
                    map.put("w", o.getW());
                }
                if (ObjectUtil.isNotEmpty(o.getH())) {
                    map.put("h", o.getH());
                }
                if (StrUtil.isNotEmpty(o.getPic())) {
                    map.put("pic", o.getPic());
                }
                if (StrUtil.isNotEmpty(o.getPicBig())) {
                    map.put("pic_big", o.getPicBig());
                }
                if (StrUtil.isNotEmpty(o.getSkuPic())) {
                    map.put("sku_pic", o.getSkuPic());
                }
                if (StrUtil.isNotEmpty(o.getName())) {
                    map.put("name", o.getName());
                }
                if (StrUtil.isNotEmpty(o.getRemark())) {
                    map.put("remark", o.getRemark());
                }
                if (StrUtil.isNotEmpty(o.getPropertiesValue())) {
                    map.put("properties_value", o.getPropertiesValue());
                }
                if (StrUtil.isNotEmpty(o.getShortName())) {
                    map.put("short_name", o.getShortName());
                }
                if (ObjectUtil.isNotEmpty(o.getWeight())) {
                    map.put("weight", o.getWeight());
                }
                if (o.getEnabled() != null) {
                    map.put("enabled", o.getEnabled());
                }
                if (StrUtil.isNotEmpty(o.getSupplierName())) {
                    map.put("supplier_name", o.getSupplierName());
                }
                if (StrUtil.isNotEmpty(o.getSkuCode())) {
                    map.put("sku_code", o.getSkuCode());
                }
                if (StrUtil.isNotEmpty(o.getSupplierSkuId())) {
                    map.put("supplier_sku_id", o.getSupplierSkuId());
                }
                if (StrUtil.isNotEmpty(o.getSupplierIId())) {
                    map.put("supplier_i_id", o.getSupplierIId());
                }
                if (ObjectUtil.isNotEmpty(o.getOtherPrice1())) {
                    map.put("other_price_1", o.getOtherPrice1());
                }
                if (ObjectUtil.isNotEmpty(o.getOtherPrice2())) {
                    map.put("other_price_2", o.getOtherPrice2());
                }
                if (ObjectUtil.isNotEmpty(o.getOtherPrice3())) {
                    map.put("other_price_3", o.getOtherPrice3());
                }
                if (ObjectUtil.isNotEmpty(o.getOtherPrice4())) {
                    map.put("other_price_4", o.getOtherPrice4());
                }
                if (ObjectUtil.isNotEmpty(o.getOtherPrice5())) {
                    map.put("other_price_5", o.getOtherPrice5());
                }
                if (StrUtil.isNotEmpty(o.getOther1())) {
                    map.put("other_1", o.getOther1());
                }
                if (StrUtil.isNotEmpty(o.getOther2())) {
                    map.put("other_2", o.getOther2());
                }
                if (StrUtil.isNotEmpty(o.getOther3())) {
                    map.put("other_3", o.getOther3());
                }
                if (StrUtil.isNotEmpty(o.getOther4())) {
                    map.put("other_4", o.getOther4());
                }
                if (StrUtil.isNotEmpty(o.getOther5())) {
                    map.put("other_5", o.getOther5());
                }
                if (ObjectUtil.isNotEmpty(o.getStockDisabled())) {
                    map.put("stock_disabled", o.getStockDisabled());
                }
                if (ObjectUtil.isNotEmpty(o.getCPrice())) {
                    map.put("c_price", o.getCPrice());
                }
                if (ObjectUtil.isNotEmpty(o.getMarketPrice())) {
                    map.put("market_price", o.getMarketPrice());
                }
                if (StrUtil.isNotEmpty(o.getUnit())) {
                    map.put("unit", o.getUnit());
                }
                if (o.getLabels() != null && o.getLabels().size() > 0) {
                    map.put("labels", o.getLabels());
                }
                if (ObjectUtil.isNotEmpty(o.getBatchEnabled())) {
                    map.put("batch_enabled", o.getBatchEnabled());
                }
                if (ObjectUtil.isNotEmpty(o.getIsSeriesNumber())) {
                    map.put("is_series_number", o.getIsSeriesNumber());
                }
                if (StrUtil.isNotEmpty(o.getOtherCode())) {
                    map.put("other_code", o.getOtherCode());
                }
                if (o.getShelfLife() != null) {
                    map.put("shelf_life", o.getShelfLife());
                }
                list.add(map);
            });
        }
        Map<String, Object> params = new HashMap<>();
        params.put("items", list);
        return HttpHelper.sendRequest(params, url);
    }

    @Override
    protected CommonProductUploadResponse process(JSONObject data, List<CommonProductUploadRequest> commonProductUploadRequests) throws Exception {
        return null;
    }
}
